class Canvas {
  constructor(canvasDom,w, h) {
    if (typeof canvasDom === 'string') {
      canvasDom = document.querySelector(canvasDom)
    }
    if (!canvasDom) {
      console.error('请输入canvas节点')
      return
    }
    const canvas = (this.canvas = canvasDom
      ? canvasDom
      : document.createElement('canvas'))

    const ctx = (this.ctx = canvas.getContext('2d'))
    
    w = w || document.documentElement.clientWidth
    h = h || document.documentElement.clientHeight

    canvas.style.width = w + 'px'
    canvas.style.height = h + 'px'
    w *= PixelRatio
    h *= PixelRatio
    canvas.width = w
    canvas.height = h
    ctx.scale(PixelRatio, PixelRatio)
  }
  get base64Img() {
    return this.canvas.toDataURL()
  }
  get context() {
    return this.ctx
  }
  get canvasWrap() {
    return this.canvas
  }
}
